Skip to main content

More on List

Different Ways of Copying a List

  • There are a number of ways to clone or copy a list in python

Using the Slicing Technique: Fastest Way

a = [1,2,3,4,4]
b = a[::] #same as a[:]
#b = a[::-1] #to copy and reverse
a[-1] = 5
print(a)
print(b)

Using the copy() Method

a = [1,2,3,4,4]
b = a.copy()
a[-1] = 5
print(a)
print(b)